package com.example.demo5datajpa.domain;

import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * @author : zhuyanpeng.zhuyanpeng
 * @Description: :
 * @date :Create in  2019/6/21- 17:55
 * @Version: V1.0
 * @Modified By:
 **/
@Data
@NoArgsConstructor
public class DeptInfo  extends Dept implements Serializable {

    @Transient
    List<User> users;


    @ManyToMany(cascade= CascadeType.REFRESH,fetch= FetchType.LAZY)
    @JoinTable(name="user_dept",//中间表名字
            joinColumns=@JoinColumn(name="dept_id",referencedColumnName="id"),
            inverseJoinColumns=@JoinColumn(name="user_id",referencedColumnName="id"))
    //所有JoinColumn 配置 name都是中间表的字段 referencedColumnName都是对应表的字段 并非实体属性
    public List<User> getUsers() {
        return users;
    }
}
